const path = require('path')
const webpack = require('webpack')
//const HtmlWebpackPlugin = require('html-webpack-plugin')
//const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf.js')

const devWebpackConfig = merge(baseWebpackConfig, {
    entry: {
        // index: './src/js/index.js',
    },
    output: {
        filename: 'js/[name].[hash:7].js',
        path: path.resolve()+'/dist'
    },
    module: {
        rules: [
            {
                test: /\.(css|scss|sass)$/,
                use: [
                    {loader: 'style-loader'},
                    {loader: 'css-loader', options: {importLoaders: 2}},
                    {loader: 'postcss-loader'},
                    {loader: 'sass-loader'}
                ]
            }
        ]
    },
    // 对应的插件
    plugins: [
        // 热更新
        new webpack.HotModuleReplacementPlugin(),

        // 复制静态目录
        new CopyWebpackPlugin([
            {
                from: 'src/assets',
                to: './assets',
                toType: 'dir'
            }
        ]),
    ],

    // vue 项目的配置
    /*devServer: {
        clientLogLevel: 'warning',
        historyApiFallback: {
            rewrites: [
                { from: /.*!/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
            ],
        },
        hot: true,
        contentBase: false, // since we use CopyWebpackPlugin.
        compress: true,
        host: HOST || config.dev.host,
        port: PORT || config.dev.port,
        open: config.dev.autoOpenBrowser,
        overlay: config.dev.errorOverlay
            ? { warnings: false, errors: true }
            : false,
        publicPath: config.dev.assetsPublicPath,
        proxy: config.dev.proxyTable,
        quiet: true, // necessary for FriendlyErrorsPlugin
        watchOptions: {
            poll: config.dev.poll,
        }
    },*/

    // 开发服务器配置(开发环境中设置)
    devServer: {
        clientLogLevel: 'warning',
        hot: true,
        contentBase: path.join(__dirname, "dist"), // 本地服务器静态文件根目录
        compress: true, // 服务器返回浏览器的时候是否启动gzip压缩
        host: 'localhost',
        port: 8080, // 端口
        //open: true,

        inline: true, // 用来支持dev-server自动刷新的配置
        overlay: {
            warnings: false,
            errors: true
        }
    },
    // 模式配置
    mode: 'development'
})


module.exports = devWebpackConfig
